<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>重置密码</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="shortcut icon" th:href="@{../../favicon.ico}" type="image/x-icon"/>
    <link rel="stylesheet" th:href="@{../../css/font.css}">
    <link rel="stylesheet" th:href="@{../../css/xadmin.css}">
    <link rel="stylesheet" th:href="@{../../css/login.css}">
    <script charset="utf-8" th:src="@{../../lib/layui/layui.js}" type="text/javascript"></script>
    <!--    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>-->
    <script th:src="@{../../js/jquery-3.5.1.min.js}" type="text/javascript"></script>
</head>
<body class="login-bg">

<div class="logo">
    <img alt="西安建筑科技大学总务处" src="" th:src="@{../../images/logo.png}">
</div>

<div class="login">
    <div class="message">后台管理员重置密码</div>
    <div style="width: 100%; height: 30px"></div>

    <form class="layui-form" id="resetInfo">
        <label for="password">新密码
            <input autocomplete="off" class="layui-input" id="password" lay-verify="L_pwd" placeholder="请输入新的登录密码"
                   type="password">
        </label>
        <hr class="hr15">
        <label for="rePassword">确认新密码
            <input class="layui-input" id="rePassword" lay-verify="L_rePwd" placeholder="请确认新密码" required="required"
                   type="password">
        </label>
        <hr class="hr15">
        <input class="layui-btn" lay-filter="resetPwd" lay-submit="" type="submit" value="重置密码">
        <hr class="hr15">
    </form>
</div>

<div class="copyright">
    <a href="http://zwc.xauat.edu.cn/" style="color: white" target="_blank">版权所有　© 西安建筑科技大学总务处</a>
</div>

<script>
    layui.use(['form', 'layer', 'jquery'], function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        // 自定义验证规则
        form.verify({
            L_pwd: [/(.+){6,12}$/, '密码必须6到12位']
            , L_rePwd: function (value) {
                if ($("#password").val() !== value) {
                    return "两次密码输入不一致";
                }
            }
        });

        //监听提交
        form.on('submit(resetPwd)',
            function () {
                var password = document.getElementById("password").value;
                //发异步，把数据提交给后端
                $.ajax({
                    url: "/admin/resetPwd",
                    data: {
                        password: password
                    },
                    type: "post",
                    dataType: "json",
                    success: function (data) {
                        console.log(data);
                        if (data.code === 0) {
                            layer.msg(data.msg, {icon: 1, time: 1500, shade: 0.4}, function () {
                                window.location.href = "/admin/login";
                            });
                        } else {
                            layer.confirm(data.msg, {
                                btn: ['登录', '返回'] //按钮
                            }, function () {
                                layer.msg('正在跳转登录页面，请稍等...', {icon: 1, time: 1500, shade: 0.4}, function () {
                                    window.location.href = "/admin/login";
                                });
                            }, function () {
                                window.location.reload();
                            });
                        }
                    }
                });
                return false;
            });

    });
</script>

</body>
</html>